<template>
  <div class="content">
    <LoginHeader />
    <Myinput
      :rule="/^\w{3,12}$/"
      errMsg="小可爱，你选择的用户名不符合标准哦，请重新输入哟"
      type="text"
      placeholder="用户名 / 手机号码"
      @setValue="setUsername"
    />
    <Myinput
      :rule="/^.{3,12}$/"
      errMsg="小可爱，你输入的昵称不符合标准哦，请重新输入哟"
      type="test"
      placeholder="昵称"
      @setValue="setNickname"
    />
    <Myinput
      :rule="/^\d{3,12}$/"
      errMsg="小可爱，你输入的密码不符合标准哦，请重新输入哟"
      type="password"
      placeholder="密码"
      @setValue="setPassword"
    />
    <Mybtn btnText="注册" @click.native="register" />
  </div>
</template>

<script>
import LoginHeader from "../components/LoginHeader";
import Myinput from "../components/Myinput";
import Mybtn from "../components/Mybtn";
export default {
  components: {
    Myinput,
    LoginHeader,
    Mybtn,
  },
  data() {
    return {
      username: "",
      nickname: "",
      password: "",
    };
  },
  methods: {
    setUsername(newVal) {
      this.username = newVal;
      console.log(this.username);
    },
    setNickname(newVal) {
      this.nickname = newVal;
      console.log(this.nickname);
    },
    setPassword(newVal) {
      this.password = newVal;
      console.log(this.password);
    },
    register() {
      this.$axios({
        method: "post",
        url: "/register",
        data: {
          username: this.username,
          nickname: this.nickname,
          password: this.password,
        },
      }).then((res) => {
        console.log(res.data);
        const { message } = res.data;
        if (message == "注册成功") {
          this.$toast.success("恭喜小可爱，成为我们的新用户啦");
        }
        // else {
        //   this.$toast.fail("哎呀！注册失败了呀");
        // }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.content {
  padding: 20 / 360 * 100vw;
}
</style>
